package appjam;

import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class InsertJamServlet extends HttpServlet {
	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String title = req.getParameter("title").replace("+", " ");
		String description = req.getParameter("description").replace("+", " ");
		String latitude = req.getParameter("lat");
		String longitude = req.getParameter("lon");
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
		
		Jam jam = new Jam(title, description, latitude, longitude);
		
		try {
			pm.makePersistent(jam);
		} finally {
			pm.close();
		}
		
		resp.sendRedirect("/index.html");
	}
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		doPost(req, resp);
	}

}
